/*
 * Copyright 2007-2008, www.jsemantic.org, www.adolfoestevez.com,
 * http://semanticj2ee.blogspot.com/ 
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.jsemantic.servicerules.drools.rules.config;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.WeakHashMap;

import org.jsemantic.core.RuleSessionFactory;
import org.jsemantic.core.context.external.ExternalContext;
import org.jsemantic.core.context.external.MapExternalContext;
import org.jsemantic.servicerules.drools.rules.DroolsRuleSessionFactoryImpl;

/**
 * The Class Config.
 */
public class Config {
	
	/** The rule file. */
	public static  String ruleFile = "org/jsemantic/servicerules/par-impar.drl";
	
	/**
	 * Gets the even facts.
	 * 
	 * @return the even facts
	 */
	public static Collection getEvenFacts() {
		List facts = new ArrayList();
		Random r = new Random();
		for (int i = 0; i < 10; i++) {
			facts.add(new Integer(r.nextInt() % 100));
		}
		return facts;
	}
	
	/**
	 * Gets the session variables.
	 * 
	 * @return the session variables
	 */
	public static Map getSessionVariables() {
		Map variables = new WeakHashMap();
		variables.put("test", "test");
		return variables;
	}
	
	/**
	 * Gets the external context.
	 * 
	 * @return the external context
	 */
	public static ExternalContext getExternalContext() {
		Map objects = new WeakHashMap();
		objects.put("1", new String("Service 1"));
		objects.put("2", new String("Service 1"));

		ExternalContext ctx = new MapExternalContext(objects);
		return ctx;
	}
	
	/**
	 * Gets the rule session factory.
	 * 
	 * @return the rule session factory
	 */
	public static RuleSessionFactory getRuleSessionFactory() {
		RuleSessionFactory factory = new DroolsRuleSessionFactoryImpl(ruleFile);
		return factory;
	}
	
}
